home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-16 | 2.5 KB | 66 lines | [TEXT/PJMM] |
- {This is Pascal source code which will compile into}
- {an xCOD (eXternal CODe) resource for NumberCrunch II.}
- {}
- {All variables passed MUST be declared var and }
- {MUST be extended or array of extended or external procedures.}
- {}
- { After building this code resource you must install it into NumberCrunch with either ResEdit or the}
- { Load xCOD command from inside NCII. }
- {}
- { In either case, an sCOD string or resource is also needed to tell NCII what the arguments to this routine are.}
- { For this routine, the appropriate sCOD is:}
- {}
- { xCOD xSCHRODINGER(N,C,E:num; V,Psi:RealArray), calculates Psi[3…N] from V[1…N], Psi[1],Psi[2],Energy, and C=dx^2*2m/hbar^2 }
- {}
- { (Of course, the sCOD string doesn't include the braces at the beginning and end of the line.) }
- {}
- { •••••••••••••••••••••••••••••}
- { •••••••• SCHRODINGER ••••••••• }
- { •••••••••••••••••••••••••••••}
- {}
- { This routine calculates Psi, the time-independent wavefunction, from V(x) and E. The equation is}
- { -hbar^2 ∂^2/∂x^2 Psi(x) + V(x) Psi(x) = E Psi(x) }
- { or Psi[i+1] - 2 Psi[i] + Psi[i-1] = C ( V[i] - E ) Psi[i] }
- { where Psi [ i ] = a discrete version of Psi [ x ] }
- { V[i] = a discrete V(x), and}
- { C = Δx^2 * 2m/hbar^2 .}
- {}
- { The program just loops from i=2 to N-1 applying Psi[i+1] = 2 Psi[i] - Psi[i-1] + C* (V[i] - E )*Psi[i]. }
- {}
- { If V is even, then the wavefunction will be even or odd, so good choices for Psi[1] and Psi[2] are }
- { [a,a] or [a,-a] for any number a . ( Psi isn 't normalized yet, so the value of "a" doesn' t really matter.) }
- { The 1st choice forces Psi to be even near x=0, while the 2nd makes it odd.}
- {}
- {}
- { INPUTS:}
- { N number of points in arrays}
- { C constant = Δx^2 * 2m / hbar^2 }
- { E the energy of the wavefunction}
- { V [1..N] array of points giving V(x), the potential. All must bet set. }
- { Psi [1..N] array of points for wavefunction. Psi[1] and Psi[2] must be set on input. }
- {OUTPUT:}
- { Psi Psi[3..N] are calculated by this subroutine.}
-
- unit SCHRODINGER;
- interface
- uses
- SANE;
-
- type
- ExtendedArrayType = array[1..1] of extended;
-
- procedure Main (var N, C, E: extended; {}
- var V, Psi: ExtendedArrayType);
-
- implementation
-
- procedure Main;
- var
- intN, i: Integer;
- begin
- intN := Num2Integer(N); {Num2Integer is a routine in the SANE library to convert extended to integer.}
- for i := 2 to (intN - 1) do
- Psi[i + 1] := Psi[i] * (2.0 + C * (V[i] - E)) - Psi[i - 1];
- end; {Main}
-
- end.